package com.cbgolf.oa.util;

import android.util.Log;

/**
 * Created by lq on 2017/10/11.
 */

public class TypeUtil {

  public static long parseLong(Object obj) {
    try {
      return Long.parseLong(obj.toString());
    } catch (Exception e) {

    }
    return -1;
  }

  public static int parseInt(Object obj) {
    try {
      return Integer.parseInt(obj.toString());
    } catch (Exception e) {

    }
    return 0;
  }

  public static float parseFloat(Object obj) {
    try {
      return Float.parseFloat(obj.toString());
    } catch (Exception e) {

    }
    return 0;
  }

  public static double parseDauble(Object obj) {
    try {
      return Double.parseDouble(obj.toString());
    } catch (Exception e) {

    }
    return 0;
  }

  public static int getInt(Object obj) {
    try {
      return Util.isDouble(obj) ? (int) Float.parseFloat(obj.toString())
          : Integer.parseInt(obj.toString());
    } catch (Exception e) {

    }
    return 0;
  }

  public static int getInt(Object obj, int defaul) {
    try {
      return Util.isDouble(obj) ? (int) Float.parseFloat(obj.toString())
          : Integer.parseInt(obj.toString());
    } catch (Exception e) {

    }
    Log.e("defaul--------", defaul + "-------");
    return defaul;
  }

  public static float zeroFloat(float num, float defaul) {
    return (num > 0 ? num : defaul);
  }

  public static long zeroLong(long l, long defaul) {
    return (l > 0 ? l : defaul);
  }

}
